package com.zhengyisky.mapper;

import com.zhengyisky.entity.Chapter;
import com.zhengyisky.entity.News;
import com.zhengyisky.entity.QueryParam;
import com.zhengyisky.entity.Type;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NewsMapper {

    @Select("select * from tb_news")
    List<News> list();

    @Select("select * from tb_type")
    List<Type> typeList();

    @Insert("insert into tb_news set title=#{title},author=#{author},pic=#{pic},status=0,publish_time=now(),type_id=#{typeId}")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void saveNews(News news);

    @Insert("insert into tb_chapter set news_id=#{newsId}, chapter_title=#{chapterTitle}, content=#{content}")
    void saveChapter(Chapter chapter);

    Integer count(QueryParam queryParam);


    List<News> listPage(QueryParam queryParam);

    @Update("update tb_news set status=1,approve_time=now() where id=#{id}")
    void pass(Integer id);

    @Select("select * from tb_news where id=#{id}")
    News findNewsById(Integer id);

    @Select("select * from tb_chapter where news_id=#{id}")
    List<Chapter> findChapterById(Integer id);

    @Update("update tb_news set status=2,approve_time=now(),reason=#{reason} where id=#{id}")
    void notPass(Integer id, String reason);
}
